Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Creating and Configuring Attribute Sets

You create a new attribute set by calling the Q3AttributeSet_New function. You configure the attribute set by adding the desired attributes to the set, using the Q3AttributeSet_Add function. Finally, you attach the configured attribute set to an object by calling an appropriate QuickDraw 3D routine. For example, to attach an attribute set to a vertex of a triangle, you call the function Q3Triangle_SetVertexAttributeSet . Listing 8 illustrates how to set the three vertices of a triangle to a specific diffuse color.

Listing 8 Creating and configuring a vertex attribute set

TQ3Status MySetTriangleVerticesDiffuseColor
                    (TQ3GeometryObject triangle, TQ3ColorRGB color)
{
    TQ3AttributeSet                 myAttrSet;      /*attribute set*/
    TQ3Status                       myResult;       /*result code*/
    unsigned long                   myIndex;        /*vertex index*/

    /*Create a new empty attribute set.*/
    myAttrSet = Q3AttributeSet_New();
    if (myAttrSet == NULL)
        return (kQ3Failure);
    /*Add the specified color attribute to the attribute set.*/
    myResult = Q3AttributeSet_Add
                (myAttrSet, kQ3AttributeTypeDiffuseColor, &color);
    if (myResult == kQ3Failure)
        return (kQ3Failure);

    /*Attach the attribute set to each triangle vertex.*/
    for (myIndex = 0; myIndex < 3; myIndex++) {
        myResult = Q3Triangle_SetVertexAttributeSet
                                        (triangle, myIndex, myAttrSet);
        if (myResult == kQ3Failure)
            return (kQ3Failure);
    }

    return (kQ3Success);
}

You can assign any number of different attribute types to a single attribute set. The function defined in Listing 8 assigns only one attribute--a diffuse color--to the new attribute set.

If you want to change the value of a certain attribute in an attribute set, you can simply overwrite the data associated with that attribute by calling Q3AttributeSet_Add once again. You can remove an attribute from an attribute set by calling Q3AttributeSet_Clear . To remove all attributes from an attribute set, you can call Q3AttributeSet_Empty .


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |